- @title = t('.heading', group: link_to(@group.name, @group)).html_safe

.row

  .col-md-8
    - if @logged_in.can_update?(@group) and @requests.any?
      = form_tag batch_group_memberships_path(@group) do |form|
        .box.box-warning
          .box-header
            %h3.box-title= t('memberships.requests.heading')
          .box-body
            %table.table.print-full-width
              %tr
                %th
                %th
                %th= t('memberships.requests.name')
                %th= t('memberships.requests.created_at')
              - @requests.each do |req|
                %tr.row-with-avatar
                  %td
                    = check_box_tag 'ids[]', req.person.try(:id), false, class: 'checkbox'
                  %td.avatar
                    = avatar_tag req.person
                  %td
                    = link_to req.person.try(:name), req.person
                  %td
                    = req.created_at.to_s(:date)
          .box-footer
            .form-group
              = t('memberships.requests.select_some')
            .form-group
              = button_tag name: 'commit', value: 'accept', class: 'btn btn-success' do
                = icon 'fa fa-plus-circle'
                = t('memberships.requests.accept.button')
              = button_tag name: 'commit', value: 'ignore', class: 'btn btn-danger' do
                = icon 'fa fa-minus-circle'
                = t('memberships.requests.ignore.button')

    = pagination @memberships

    - if @group.people.any?
      = form_tag batch_group_memberships_path(@group), method: :delete do
        %table.members.table.print-full-width
          %thead
            %tr
              - if @logged_in.can_update?(@group)
                %th
              %th
              %th= link_to t('.details.name'), "?order=#{params[:order] == 'last' ? 'first' : 'last'}"
              - if params[:birthdays]
                %th= t('.details.birthday')
              - else
                %th= t('.details.created_at')
              - if @logged_in.can_update?(@group)
                %th= t('.details.admin')
                %th= t('.details.leader')
          %tbody#memberships
            - @memberships.includes(:person).order('people.last_name', 'people.first_name').each do |membership|
              - if person = membership.person
                = render partial: 'membership', object: membership

        - if @logged_in.can_update?(@group)
          .page-controls
            = button_tag class: 'btn btn-delete' do
              = icon 'fa fa-minus-circle'
              = t('.remove.button')

    - else
      %p= t('none')

    = pagination @memberships

  .col-md-4.hidden-print
    - if @logged_in.can_update?(@group)
      .box.box-success
        .box-header
          %h3.box-title
            = t('memberships.add.heading')
        .box-body
          - if @group.approved?
            = form_tag search_path, remote: true do
              = hidden_field_tag :select_person, true
              .form-group
                = label_tag :add_person_name do
                  = t('memberships.add.description')
                = text_field_tag 'name', nil, id: 'add_person_name', class: 'form-control', placeholder: t('memberships.add.name_placeholder')
                - if @group.parents_of?
                  .callout.callout-danger.push-down
                    = t('memberships.add.parents_of_warning_html', group: link_to(@group.parents_of_group.try(:name), @group.parents_of_group))
                - elsif @group.linked?
                  .callout.callout-danger.push-down
                    = t('memberships.add.linked_group_warning_html', code: @group.link_code)
              .form-group
                = button_tag t('search.search_by_name'), class: 'btn btn-info'
            #add_member{ style: 'display:none' }
              = form_tag batch_group_memberships_path(@group), remote: true, id: 'add_people_form' do
                = hidden_field_tag(:birthdays, true) if params[:birthdays]
                #results
                %p= button_tag t('search.add_selected'), class: 'btn btn-success'
          - else
            %p.very-strong
              = t('memberships.group_pending_approval')
